import getInfo from "../pages/noticeApp/utils/getInfo"
import Taro from "@tarojs/taro"
import MyUtils from "../pages/noticeApp/components/personal/utils"

/**根据系统id获取子系统地址 */
export const getSubsystemBySystemId = (systemId = "220") => {
    return new Promise((resolve, reject) => {
        Taro.request({
            url:'https://campus.lancooedu.com/school/getSubsystemBySystemId',
            method:"GET",
            data:{
                schoolId:getInfo.getSchoolId(),
                systemId:systemId
            },
            success(res){
                console.log("API-子系统地址:",res)
                if(!res.data.data.url){
                  console.log("[x]无"+ systemId +"子系统地址")
                  Taro.showToast({
                    title:"子系统地址为空",
                    icon:"none",
                    duration:2000
                  })
                }else{
                  MyUtils.setStorage("baseUrl" + systemId, res.data.data.url)
                  resolve(res.data.data.url)
                }
            }
        })
    })
}

/**校园通获取基础平台地址 */
export const getUrlBySchoolId = () => {
  return new Promise((resolve, reject) => {
    Taro.request({
      url:'https://campus.lancooedu.com/school/getUrlBySchoolId',
      method:"GET",
      data:{
        schoolId:getInfo.getSchoolId()
      },
      success(res){
        console.log("API-校园通获取基础平台地址",res)
        if(!res.data.data.url){
          console.log("[x]无基础平台地址")
        }else{
          MyUtils.setStorage("baseUrl",res.data.data.url)
        }
      }
    })
  })
}